package com.zxc.service.impl;




import com.zxc.dao.EquipmentDao;
import com.zxc.dao.ParkDao;
import com.zxc.model.Equipment.Equipment;
import com.zxc.model.Equipment.EquipmentApply;
import com.zxc.model.ParkDaily.ParkState;
import com.zxc.model.ParkDetails;
import com.zxc.model.seeds;
import com.zxc.service.ParkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;


@Service
public class ParkServiceImpl implements ParkService {
    @Autowired
    private EquipmentDao equipmentDao;

    @Autowired
    private ParkDao parkDao;

    public  List<Equipment> printEquipment(String id){
        List<Equipment> list = equipmentDao.selectEquipmentByParkId(id);
    return  list;
    }

    public  List<Equipment> selectEquipmentByAccount(Equipment equipment){
        List<Equipment> list = equipmentDao.selectEquipmentByAccount(equipment);
        return  list;
    }


    public  List<Equipment> selectEquipmentByUserAccount(Equipment equipment){
        List<Equipment> list = equipmentDao.selectEquipmentByUserAccount(equipment);
        return  list;
    }

    public  List<EquipmentApply> selectEquipmentState(EquipmentApply equipment){
        List<EquipmentApply> list = equipmentDao.selectEquipmentState(equipment);
        return  list;
    }
    public int setEquipmentState(EquipmentApply equipmentApply){
        int i= -1;
        Equipment equipment1=new Equipment();
        equipment1.setId(equipmentApply.getEquipmentId());
        equipment1.setEquipmentStatus(equipmentApply.getEquipmentStatus());
        i=equipmentDao.updateUserEquipmentWarehouse(equipment1);
        if (i>0){
            i+=equipmentDao.updateEquipmentApply(equipmentApply);
            return i;
        }else {
            return  i;
        }
    }
    public int updateRowState(Equipment equipment){
        int i=equipmentDao.updateTrading(equipment);
        return i;
    }
    public int setEquipmentApply(EquipmentApply equipmentApply){
        equipmentApply.setId(UUID.randomUUID().toString().replaceAll("-", ""));
        equipmentApply.setState(1);
        Equipment equipment = new Equipment();
        equipment.setId(equipmentApply.getEquipmentId());
        equipment.setEquipmentStatus("4");
        equipmentDao.updateTrading(equipment);
        int i=equipmentDao.insertEquipmentApply(equipmentApply);
        return  i;
    }

    public int deleteEquipmentById(Equipment equipment){
        int i=equipmentDao.deleteEquipment(equipment);
        return i;
    };
    //管理员和用户获取设备仓库信息
    //管理员
    public List<Equipment> getEquipmentWarehouseRoot(Equipment equipment){
        List<Equipment> list = equipmentDao.getEquipmentWarehouseRoot(equipment);
        return list;
    }
    //普通用户
    public List<Equipment> getEquipmentWarehouseUser(Equipment equipment){
        List<Equipment> list = equipmentDao.getEquipmentWarehouseUser(equipment);
        return list;
    }

    public List<ParkState> getParkData(ParkState parkState){
//        parkDetails
        return parkDao.selectParkData(parkState);
    }
    public int setNewParkData(ParkState parkState)
    {   parkState.setId(UUID.randomUUID().toString().replaceAll("-", ""));
        parkState.setUserId("kxzt");
        parkState.setPlantId("zwzhj");
        parkState.setParkState("3");
        return parkDao.insertParkData(parkState);
    }
    public List<seeds> getPlant(){
        return  parkDao.selectPlant();
    }




}
